/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/6/20
 * \* Time: 20:50
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 继承 {
    class person{
        private String name;
        private int age;

        public person(String name,int age){
            this.name=name;
            this.age=age;
        }
        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    class student extends person{
        // 不要重复name和age字段/方法,
        // 只需要定义新增score字段/方法:
        private int score;

        public int getScore() {
            return score;
        }

        public void setScore(int score) {
            this.score = score;
        }

        /**
         * 在Java中，任何class的构造方法，第一行语句必须是调用父类的构造方法。如果没有明确地调用父类的构造方法，编译器会帮我们自动加一句super();
         */
        public student(String name,int age,int score){
            super(name,age);
            this.score=score;
        }


        /**
         * 继承有个特点，就是子类无法访问父类的private字段或者private方法,改成proteced就可以了
         */
//        public String hello(){
//            return name;//非法访问
//        }
    }



}